<?php namespace App\Http\Controllers\Admin;

// use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Services\Categories as sCategories;
use App\Models\Categories   as mCategories;
use Illuminate\Http\Request;

use DB;

class CategoriesController extends BaseController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		$categories = sCategories::getCategoriesList();
		
		return $this->view('categories.index',compact('categories'));
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		return $this->view('categories.create');
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store(Request $request)
	{
		try{
			DB::beginTransaction();

			$data = $request->all();
			
			mCategories::create($data);

			DB::commit();

			return $this->redirect('categoires.index');

		}catch(\Exception $e){

			DB::rollback();

			return $this->redirect('categories.index');
		}


	
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		mCategories::where('cat_id',$id)->update(['status' => mCategories::DELETE_STATUS]);
		
		return $this->redirect('categories.index');
	}

}
